#INCLUDE "PROTHEUS.CH"
#INCLUDE "APWEBEX.CH"
/*/{Protheus.doc} DTRWEB05

@descricao RESUMO DE HORAS

@author Peterson Scherwinski

@since 05/12/2014

/*/
User Function DTRWEB05
	Local cHtml	:= ""
	local oObj
	local cPagina	:= "DTRHTM05"//pagina a ser apresentada
	local dDataRef := stod(substr(dtos(date()),1,6)+"01")

	Web Extended Init cHtml// START "init"

		//controle de acesso / timeout
		if type("HTTPSESSION->USERLOGIN") <> "A"
			HTTPSESSION->ALERT	:= "Necessario efetuar o login."
			RETURN( RedirPage('/U_DTRWEB01.apw'))
		endif
		
		HttpSession->AMESES := {}//6 MESES RETROATIVOS
		HttpSession->RESUMOHS	:= {}
		HttpSession->NTOTALHS	:= 0
		HttpSession->CompetSel	:= dtoc(dDataRef)
		
		for nx := 1 to 6
			aAdd(HttpSession->AMESES,dDataRef)

			nMes	:= month(dDataRef)
			nAno	:= year(dDataRef)
			if nMes == 1
				nAno := nAno -1
				nMes := 12
			else
				nMes	:= nMes -1
			endif
			
			dDataRef := stod(strzero(nAno,4)+strzero(nMes,2)+"01")
			
		next
		
		//carrega resumo de horas da competencia informada
		if !empty(HTTPGET->COMPET)
			HttpSession->CompetSel := HTTPGET->COMPET
		endif 

		//VALIDAR E SALVAR AS AGENDAS
		oObj := WSDTRWEBSR():New()
		
		oObj:CTOKEN 		:= "DATAROUTEWEB"
		oObj:cCODRESOURSE	:=	HTTPSESSION->USERLOGIN[4]//RECURSO
		oObj:cDateStart	:= HttpSession->CompetSel
		
		if oObj:GETRESUMO()
			//TOTAL
			HttpSession->NTOTALHS	:= oObj:OWSGETRESUMORESULT:NNTOTAL
			//LISTAGEM DE OS
			FOR NX:=1 TO LEN(oObj:OWSGETRESUMORESULT:OWSAPTOS:OWSRESUMOS)
				oResumo := oObj:OWSGETRESUMORESULT:OWSAPTOS:OWSRESUMOS[nx]
					
				aAdd(HttPSession->RESUMOHS,{;
					oResumo:cDATA,;
					oResumo:cPROJETO,;
					oResumo:cTAREFA,;
					oResumo:cHORAINI,;
					oResumo:cHORAFIM,;
					oResumo:cOUTROS,;
					oResumo:cTOTAL;
					})
			NEXT
			
		endif
		
		execInPage(cPagina)
	
	Web Extended End

return(cHtml)
